package com.kexio.email.config;

import org.springframework.boot.context.properties.ConfigurationProperties;

/**
 * 邮件服务配置属性
 * 
 * @author Kexio Team
 * @since 1.0.0
 */
@ConfigurationProperties(prefix = "kexio.email")
public class EmailProperties {
    
    /**
     * 是否启用邮件服务
     */
    private boolean enabled = false;
    
    /**
     * SMTP服务器配置
     */
    private SmtpConfig smtp = new SmtpConfig();
    
    /**
     * 默认发件人配置
     */
    private SenderConfig sender = new SenderConfig();
    
    /**
     * 异步发送配置
     */
    private AsyncConfig async = new AsyncConfig();
    
    /**
     * 模板配置
     */
    private TemplateConfig template = new TemplateConfig();
    
    /**
     * 重试配置
     */
    private RetryConfig retry = new RetryConfig();
    
    /**
     * 限制配置
     */
    private LimitConfig limit = new LimitConfig();
    
    /**
     * 记录配置
     */
    private RecordConfig record = new RecordConfig();
    
    public static class SmtpConfig {
        private String host = "smtp.163.com";
        private int port = 587;
        private String username;
        private String password;
        private boolean auth = true;
        private boolean starttlsEnable = true;
        private boolean sslEnable = false;
        private int connectionTimeout = 30000;
        private int timeout = 30000;
        private int writeTimeout = 30000;
        
        // Getters and Setters
        public String getHost() { return host; }
        public void setHost(String host) { this.host = host; }
        
        public int getPort() { return port; }
        public void setPort(int port) { this.port = port; }
        
        public String getUsername() { return username; }
        public void setUsername(String username) { this.username = username; }
        
        public String getPassword() { return password; }
        public void setPassword(String password) { this.password = password; }
        
        public boolean isAuth() { return auth; }
        public void setAuth(boolean auth) { this.auth = auth; }
        
        public boolean isStarttlsEnable() { return starttlsEnable; }
        public void setStarttlsEnable(boolean starttlsEnable) { this.starttlsEnable = starttlsEnable; }
        
        public boolean isSslEnable() { return sslEnable; }
        public void setSslEnable(boolean sslEnable) { this.sslEnable = sslEnable; }
        
        public int getConnectionTimeout() { return connectionTimeout; }
        public void setConnectionTimeout(int connectionTimeout) { this.connectionTimeout = connectionTimeout; }
        
        public int getTimeout() { return timeout; }
        public void setTimeout(int timeout) { this.timeout = timeout; }
        
        public int getWriteTimeout() { return writeTimeout; }
        public void setWriteTimeout(int writeTimeout) { this.writeTimeout = writeTimeout; }
    }
    
    public static class SenderConfig {
        private String defaultFromEmail;
        private String defaultFromName;
        private String replyToEmail;
        private String signature;
        
        // Getters and Setters
        public String getDefaultFromEmail() { return defaultFromEmail; }
        public void setDefaultFromEmail(String defaultFromEmail) { this.defaultFromEmail = defaultFromEmail; }
        
        public String getDefaultFromName() { return defaultFromName; }
        public void setDefaultFromName(String defaultFromName) { this.defaultFromName = defaultFromName; }
        
        public String getReplyToEmail() { return replyToEmail; }
        public void setReplyToEmail(String replyToEmail) { this.replyToEmail = replyToEmail; }
        
        public String getSignature() { return signature; }
        public void setSignature(String signature) { this.signature = signature; }
    }
    
    public static class AsyncConfig {
        /**
         * 是否启用异步发送
         */
        private boolean enabled = true;
        
        /**
         * 线程池核心线程数
         */
        private int corePoolSize = 2;
        
        /**
         * 线程池最大线程数
         */
        private int maxPoolSize = 10;
        
        /**
         * 队列容量
         */
        private int queueCapacity = 1000;
        
        /**
         * 线程空闲时间 (秒)
         */
        private int keepAliveSeconds = 60;
        
        // Getters and Setters
        public boolean isEnabled() { return enabled; }
        public void setEnabled(boolean enabled) { this.enabled = enabled; }
        
        public int getCorePoolSize() { return corePoolSize; }
        public void setCorePoolSize(int corePoolSize) { this.corePoolSize = corePoolSize; }
        
        public int getMaxPoolSize() { return maxPoolSize; }
        public void setMaxPoolSize(int maxPoolSize) { this.maxPoolSize = maxPoolSize; }
        
        public int getQueueCapacity() { return queueCapacity; }
        public void setQueueCapacity(int queueCapacity) { this.queueCapacity = queueCapacity; }
        
        public int getKeepAliveSeconds() { return keepAliveSeconds; }
        public void setKeepAliveSeconds(int keepAliveSeconds) { this.keepAliveSeconds = keepAliveSeconds; }
    }
    
    public static class TemplateConfig {
        /**
         * 默认模板引擎
         */
        private String defaultEngine = "thymeleaf";
        
        /**
         * 模板缓存
         */
        private boolean enableCache = true;
        
        /**
         * 缓存过期时间 (分钟)
         */
        private int cacheExpireMinutes = 30;
        
        /**
         * 模板路径前缀
         */
        private String pathPrefix = "classpath:/templates/email/";
        
        /**
         * 模板文件后缀
         */
        private String fileSuffix = ".html";
        
        // Getters and Setters
        public String getDefaultEngine() { return defaultEngine; }
        public void setDefaultEngine(String defaultEngine) { this.defaultEngine = defaultEngine; }
        
        public boolean isEnableCache() { return enableCache; }
        public void setEnableCache(boolean enableCache) { this.enableCache = enableCache; }
        
        public int getCacheExpireMinutes() { return cacheExpireMinutes; }
        public void setCacheExpireMinutes(int cacheExpireMinutes) { this.cacheExpireMinutes = cacheExpireMinutes; }
        
        public String getPathPrefix() { return pathPrefix; }
        public void setPathPrefix(String pathPrefix) { this.pathPrefix = pathPrefix; }
        
        public String getFileSuffix() { return fileSuffix; }
        public void setFileSuffix(String fileSuffix) { this.fileSuffix = fileSuffix; }
    }
    
    public static class RetryConfig {
        /**
         * 最大重试次数
         */
        private int maxRetryCount = 3;
        
        /**
         * 重试间隔 (秒)
         */
        private int retryIntervalSeconds = 60;
        
        /**
         * 重试指数退避
         */
        private boolean exponentialBackoff = true;
        
        // Getters and Setters
        public int getMaxRetryCount() { return maxRetryCount; }
        public void setMaxRetryCount(int maxRetryCount) { this.maxRetryCount = maxRetryCount; }
        
        public int getRetryIntervalSeconds() { return retryIntervalSeconds; }
        public void setRetryIntervalSeconds(int retryIntervalSeconds) { this.retryIntervalSeconds = retryIntervalSeconds; }
        
        public boolean isExponentialBackoff() { return exponentialBackoff; }
        public void setExponentialBackoff(boolean exponentialBackoff) { this.exponentialBackoff = exponentialBackoff; }
    }
    
    public static class LimitConfig {
        /**
         * 最大附件大小 (MB)
         */
        private int maxAttachmentSizeMb = 10;
        
        /**
         * 最大附件数量
         */
        private int maxAttachmentCount = 5;
        
        /**
         * 每小时最大发送数量
         */
        private int maxSendPerHour = 100;
        
        /**
         * 每日最大发送数量
         */
        private int maxSendPerDay = 1000;
        
        // Getters and Setters
        public int getMaxAttachmentSizeMb() { return maxAttachmentSizeMb; }
        public void setMaxAttachmentSizeMb(int maxAttachmentSizeMb) { this.maxAttachmentSizeMb = maxAttachmentSizeMb; }
        
        public int getMaxAttachmentCount() { return maxAttachmentCount; }
        public void setMaxAttachmentCount(int maxAttachmentCount) { this.maxAttachmentCount = maxAttachmentCount; }
        
        public int getMaxSendPerHour() { return maxSendPerHour; }
        public void setMaxSendPerHour(int maxSendPerHour) { this.maxSendPerHour = maxSendPerHour; }
        
        public int getMaxSendPerDay() { return maxSendPerDay; }
        public void setMaxSendPerDay(int maxSendPerDay) { this.maxSendPerDay = maxSendPerDay; }
    }
    
    public static class RecordConfig {
        /**
         * 是否启用发送记录
         */
        private boolean enabled = true;
        
        /**
         * 记录保留天数
         */
        private int retentionDays = 30;
        
        /**
         * 是否记录邮件内容
         */
        private boolean saveContent = true;
        
        /**
         * 是否自动清理过期记录
         */
        private boolean autoCleanup = true;
        
        // Getters and Setters
        public boolean isEnabled() { return enabled; }
        public void setEnabled(boolean enabled) { this.enabled = enabled; }
        
        public int getRetentionDays() { return retentionDays; }
        public void setRetentionDays(int retentionDays) { this.retentionDays = retentionDays; }
        
        public boolean isSaveContent() { return saveContent; }
        public void setSaveContent(boolean saveContent) { this.saveContent = saveContent; }
        
        public boolean isAutoCleanup() { return autoCleanup; }
        public void setAutoCleanup(boolean autoCleanup) { this.autoCleanup = autoCleanup; }
    }
    
    // Main class getters and setters
    public boolean isEnabled() { return enabled; }
    public void setEnabled(boolean enabled) { this.enabled = enabled; }
    
    public SmtpConfig getSmtp() { return smtp; }
    public void setSmtp(SmtpConfig smtp) { this.smtp = smtp; }
    
    public SenderConfig getSender() { return sender; }
    public void setSender(SenderConfig sender) { this.sender = sender; }
    
    public AsyncConfig getAsync() { return async; }
    public void setAsync(AsyncConfig async) { this.async = async; }
    
    public TemplateConfig getTemplate() { return template; }
    public void setTemplate(TemplateConfig template) { this.template = template; }
    
    public RetryConfig getRetry() { return retry; }
    public void setRetry(RetryConfig retry) { this.retry = retry; }
    
    public LimitConfig getLimit() { return limit; }
    public void setLimit(LimitConfig limit) { this.limit = limit; }
    
    public RecordConfig getRecord() { return record; }
    public void setRecord(RecordConfig record) { this.record = record; }
}
